package crypt

import (
	"gitee.com/tgodfather/utility/crypt/agkey"
	ko "gitee.com/tgodfather/utility/crypt/options"
)

type Key interface {
	Load(data []byte, o ...ko.KeyOption) error
	Save(o ...ko.KeyOption) ([]byte, error)

	Sign(data []byte, o ...ko.KeyOption) ([]byte, error)
	Verify(data []byte, signature []byte, o ...ko.KeyOption) (bool, error)

	Encrypt(data []byte, o ...ko.KeyOption) ([]byte, error)
	Decrypt(data []byte, o ...ko.KeyOption) ([]byte, error)
}

func NewCryptKey() Key {

	return agkey.New()
}

// func testEnvEncode() {
// 	b64 := base64.StdEncoding

// 	// smx509.MarshalSm2PrivateKey(ab.PublicKey)
// 	// smx509.ParsePKCS8PrivateKey()
// 	// smx509.WritePrivateKeyToPem()
// 	// smx509.ReadPrivateKeyFromPem()
// 	prik, _ := sm2.GenerateKey(rand.Reader)
// 	priKM, _ := smx509.MarshalSm2PrivateKey(prik, []byte("abcde"))
// 	priHex := smx509.WritePrivateKeyToHex(prik)
// 	priPem, _ := smx509.WritePrivateKeyToPem(prik, nil)
// 	log.Println("x509 pri mar ", len(priKM), b64.EncodeToString(priKM))
// 	log.Println("x509 pri hex ", len(priHex), priHex)
// 	log.Println("x509 pri perm\n", string(priPem))

// 	pk2, _ := smx509.ReadPrivateKeyFromHex(priHex)
// 	log.Println("x509 pri load ", len(pk2.D.Bytes()), pk2.D.Bytes())

// 	// smx509.MarshalSm2PublicKey()
// 	// smx509.ParseSm2PublicKey()
// 	// smx509.WritePublicKeyToPem()
// 	// smx509.ReadPublicKeyFromPem()
// 	pubk := &prik.PublicKey
// 	pubKM, _ := smx509.MarshalSm2PublicKey(pubk)
// 	pubHex := smx509.WritePublicKeyToHex(pubk)
// 	pubPem, _ := smx509.WritePublicKeyToPem(pubk)
// 	log.Println("x509 pub mar ", len(pubKM), b64.EncodeToString(pubKM))
// 	log.Println("x509 pub hex ", len(pubHex), pubHex)
// 	log.Println("x509 pub perm\n", string(pubPem))

// 	nKey := NewTxKey("id1", ALG_TYPE_SM2_PUB, pubKM)
// 	ak1, err := asn1.Marshal(nKey)
// 	// al := []TxKey{ak1, ak1, ak1, ak1}
// 	log.Println("asn1 pub \n", ak1, err)
// 	var key2 TxKey
// 	rc, err := asn1.Unmarshal(ak1, &key2)
// 	log.Println("asn1 ukey \n", rc, err, key2)
// }
